<?php

namespace app\admin\controller;

use app\admin\BaseController;
use app\admin\model\BangfuduixiangModel;

class Interview extends BaseController
{
    public function query()
    {
        $params = $this->request->param();
        $list = BangfuduixiangModel::where('village_id',$this->villageId)
            ->paginate([
                'list_rows' => $params['pageSize'],
                'page' => $params['pageNo']
            ]);
        return show($list);
    }

    public function add()
    {
        $params = $this->request->param();

        if(empty($params['jdgb'])) {
            return show([],400,'缺少结对干部');
        }
        if(empty($params['bfdx'])) {
            return show([],400,'缺少帮扶对象');
        }
        if(empty($params['zfsj'])) {
            return show([],400,'缺少走访时间');
        }

        BangfuduixiangModel::create([
            'jdgb' => $params['jdgb'],
            'bfdx' => $params['bfdx'],
            'zfsj' => strtotime($params['zfsj']),
            'village_id' => $this->villageId
        ]);

        return show();
    }

    public function edit()
    {
        $params = $this->request->param();
        if(empty($params['jdgb'])) {
            return show([],400,'缺少结对干部');
        }
        if(empty($params['bfdx'])) {
            return show([],400,'缺少帮扶对象');
        }
        if(empty($params['zfsj'])) {
            return show([],400,'缺少走访时间');
        }

        if(empty($params['id'])) {
            return show([],400,'缺少关键参数id');
        }

        $bangfuduixiangModel = BangfuduixiangModel::find($params['id']);
        $bangfuduixiangModel->jdgb = $params['jdgb'];
        $bangfuduixiangModel->bfdx = $params['bfdx'];
        $bangfuduixiangModel->zfsj = strtotime($params['zfsj']);
        $bangfuduixiangModel->save();

        return show();

    }

    public function del()
    {
        $params = $this->request->param();

        BangfuduixiangModel::destroy($params['id']);

        return show();

    }

}